﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_QLSV.BusinessClassLibrary
{
    public class KhoaBUS
    {
        private static QLSVDataContext db = new QLSVDataContext();
        public static bool ThemKhoa(Khoa khoa)
        {
            try
            {
                db.Khoas.InsertOnSubmit(khoa);
                db.SubmitChanges();
            }
            catch
            {
                //conflict primary key - the item is exist
                return false;
            }
            return true;
        }
        public static bool XoaKhoa(string idkhoa)
        {
            try
            {
                Khoa old = db.Khoas.Single(kh => kh.masokhoa == idkhoa);
                db.Khoas.DeleteOnSubmit(old);
                db.SubmitChanges();
            }
            catch
            {
                // the item is not exist
                return false;
            }
            return true;
        }
        public static bool CapNhatKhoaHoc(string id, Khoa khoa)
        {
            try
            {
                Khoa old = db.Khoas.Single(kh => kh.masokhoa == id);
                old.tenkhoa = khoa.tenkhoa;
                db.SubmitChanges();
            }
            catch
            {
                // the item is not exist
                return false;
            }
            return true;
        }
        public static List<Khoa> LayDanhSach()
        {
            return db.Khoas.ToList();
        }
        
    }
}
